<%--
  Created by IntelliJ IDEA.
  User: Administrator
  Date: 2016/11/7
  Time: 13:27
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ include file="/mb/jsp/common.jsp" %>
<%@ page import="com.wsu.search.tools.Tools" %>
<%
String keywordVal = Tools.RmNull(request.getParameter("keywordVal"));
 %>


<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>我的销售团队</title>
</head>
<body ontouchstart="">
<div class="detailTop pf w100 of">
    <div class="w100 of tc cf f18">
        <span class="pa" style="left: 2px;" onclick="javascript:history.back();"><img src="mb/images/top_back_white.png"
                                                                                      style="margin-top: 4px;height: 40px;width: 40px;"/></span>
		我的销售团队
    </div>
</div>

<div id="container" class="container db jz mgt45">
	<section class="w100 pf bcf" style="top:45px;left:0;"> 
		<div class="w92 jz flexBox of">
			<div class="pr mgt10 mgb10" style="flex-grow: 2;">
			<input type="search" name="keyword" value="" id="teamSearch" placeholder="输入用户昵称关键词查找" class="f14 br2 db w100 teamSearch">
				<img src="mb/images/teamSearch.png" class="pa" style="height:16px;top:11px;left:10px;">
			</div>
			<input type="submit" value="搜索" name="" class="btnBlue tc db mgl10 cf br2 f15" onclick="search();" style="line-height:36px;width:19%">
		</div>

	</section>
	
	<article id="teamListContainer" class="w100 of bcf" style="margin-top: 69px;">
	 	<div id="resText"></div><!--resText-->
	</article>

      
        <div id="loading" class="w100">
            <img src="mb/images/loading.gif" alt="正在加载" class="db jz hauto" style="width: 15px;">
            <div class="w100 tc f10 c9">正在加载</div>
        </div>
         <div id="loadingComplete" class="w100" style="display:none;">
            <div class="w100 tc f12 c9">已加载完所有数据</div>
        </div>
    
</div>
 <script>
 
/*    //获取url中的参数
        function getUrlParam(name) {
            var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)"); //构造一个含有目标参数的正则表达式对象
            var r = window.location.search.substr(1).match(reg);  //匹配目标参数
            if (r != null) return unescape(r[2]); return null; //返回参数值
        }
        
     var keywordVal = getUrlParam('keywordVal'); */
     
     
	var total = 0;  
	var curpage = 1;
	var keywordVal="";
	
	
	
	
	
	/**
     * 搜索
     */
    function search() {
        keywordVal = $.trim($("#teamSearch").val());
       $("#teamListContainer").html('<div id="resText"></div><!--resText-->');
	         curpage = 1;
	       	 getData();
    }
	
   //加载新数据
    function getData() {
    keywordVal =decodeURIComponent('<%=keywordVal%>');
        $.ajax({
            url: "PlugServlet",
            data: JSON.stringify({m:1785,curpage:curpage,keyword:keywordVal}),
            type: 'post',
            dataType: 'json',
            contentType: "application/json;charset=utf-8",
            beforeSend: function () {
                showProgressDg();
            },
            success: function (data) {
               if (data.state == 1) {
                  showData(data.list);
                } else {
                    // 其他错误弹出提示
                   showToast(data.info);
                }
            },
            error: function (data) {
                showToast(data.info);
            },
            complete: function () {
                closeProgressDg();
            }
        });
        
    }

 function showData(list)
    {
    	var htmlStr="";
    	$.each(list, function(index, obj) 
    	{
    		htmlStr +='<section class="w100 b-b">'+
							'<div class="w92 jz mgt10 mgb10 df">'+
								'<div class="circle of" style="height: 54px;width:54px;"> '+
									'<img src="'+getBaseImgUrl(obj.avatar)+'" class="db w100 h100">'+	
								'</div>'+
								'<div class="mgl10" style="flex-grow: 2;">'+
									'<p class="c3 f15">'+obj.username+'<p>'+
									'<p class="c9 f14 mgt10">'+obj.time+'<p>'+
								'</div>'+
								'<div class="c3 f16"><span class="orange2">'+obj.level.substring(0,1)+'</span>'+obj.level.substring(1)+'</div>'+
							'</div>'+
						'</section>';
	    		   		
    	});
    	 $("#resText").after(htmlStr);
    	
    	
    }
   
 
	$(document).ready(function(){
			getData();
			
			$(window).scroll(function () {
	        if ($(window).scrollTop() == $(document).height() - $(window).height()) {
		           if (curpage < total) {
		               curpage++;
		                $("#loading").slideDown();
		               getData();
		               $("#loading").slideUp();
	              }
	              else {
		               	$("#loadingComplete").slideDown();
		               	var close = function (){
		               	  $("#loadingComplete").slideUp()
		               	};
		   				setTimeout(close,3000);
		   				clearTimeout(close); 
		   				return false;
	              } 
	              
	        }
	 
	    });
	    
	    
	     //按回车或者键盘搜索按钮进行搜索
        $("#teamSearch").on('keypress',function(e) {  
                var keycode = e.keyCode;  
                if(keycode=='13') {  
                    e.preventDefault();    
                    //请求搜索接口  
                    search();
                    
                }  
         });  
	   
	});
</script>


</body>
</html>
